package thread.example3;


/*

                1):Java中类是单继承的,如果继承了Thread了,该类就不能再有其他的直接父类了.
                        2):从操作上分析,继承方式更简单,获取线程名字也简单.(操作上,更简单)
                        3):从多线程共享同一个资源上分析,继承方式不能做到.
*/
public class ExtendsDemo {
    public static void main(String[] args) {
        Person p1 = new Person("A");
        p1.start();

        Person p2 = new Person("B");
        p2.start();

        Person p3 = new Person("C");
        p3.start();

    }

}

class Person extends Thread {

    private static  int num = 50;

    public Person(String name) {
        super(name);
    }

    @Override
    public void run() {
        for (int i = 0; i < 50; i++) {
            if (num > 0) {
                try {
                    Thread.sleep(10L);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
                System.out.println(Thread.currentThread().getName() + "吃了" + num-- + "号苹果");
            }
        }
    }
}
